package com.phb.puhuibao.service.impl;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.idp.pub.context.AppContext;
import com.idp.pub.dao.IBaseDao;
import com.idp.pub.dao.IPagerDao;
import com.idp.pub.service.impl.DefaultBaseService;
import com.phb.puhuibao.common.Functions;
import com.phb.puhuibao.entity.ItemInvestment;
import com.phb.puhuibao.entity.LoanItem;
import com.phb.puhuibao.entity.MobileUser;
import com.phb.puhuibao.entity.UserLoan;
import com.phb.puhuibao.entity.UserMessage;
import com.phb.puhuibao.service.MobileUserService;

@Transactional
@Service("mobileUserService")
public class MobileUserServiceImpl extends DefaultBaseService<MobileUser, String> implements MobileUserService {
	@Resource(name = "mobileUserDao")
	public void setBaseDao(IBaseDao<MobileUser, String> baseDao) {
		super.setBaseDao(baseDao);
	}

	@Resource(name = "mobileUserDao")
	public void setPagerDao(IPagerDao<MobileUser> pagerDao) {
		super.setPagerDao(pagerDao);
	}

	@Resource(name = "itemInvestmentDao")
	private IBaseDao<ItemInvestment, String> itemInvestmentDao;

	@Resource(name = "userLoanDao")
	private IBaseDao<UserLoan, String> userLoanDao;
	@Resource(name = "loanItemDao")
	private IBaseDao<LoanItem, String> loanItemDao;

	@Resource(name = "jdbcTemplate")
	private JdbcTemplate jdbcTemplate;
	@Resource(name = "appContext")
	private AppContext appContext;
	@Resource(name = "userMessageDao")
	private IBaseDao<UserMessage, String> userMessageDao;

	@Override
	public void userCreate(MobileUser entity) {
		// TODO Auto-generated method stub
		entity.setCreateTime(new Date());
		entity = this.getBaseDao().save(entity);
		
		
		UserMessage message =  new UserMessage();
		message.setUserId(entity.getUserId());
		message.setType(2);//2---系统消息
		message.setContent("得财兼贝欢迎您，您于" + new SimpleDateFormat("yyyy年MM月dd日").format(new Date()) + "开启了得财兼贝之旅！");
		userMessageDao.save(message);

	}

	

	/**
	 * 后台开户
	 * @param entity
	 */
	public void adminCreate(MobileUser entity) {
		this.save(entity);
		MobileUser user = this.getBaseDao().save(entity);
		
	}

	
}
